package org.example.gateway.spi.balancers;

import org.example.gateway.annoation.LoadBalance;
import org.example.gateway.contants.LoadBalanceConstants;
import org.example.gateway.pojo.dto.ServiceInstance;
import org.example.gateway.spi.LoadBalancer;

import java.util.List;
import java.util.Random;

@LoadBalance(LoadBalanceConstants.RANDOM)
public class RandomLoadBalancer implements LoadBalancer {
    private static Random random = new Random();

    @Override
    public ServiceInstance chooseOne(List<ServiceInstance> instances) {
        return instances.get(random.nextInt(instances.size()));
    }
}
